package io.file;

import framework.AbstractTest;
import utils.IOUtils;
import utils.StringUtils;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

/**
 * Created by shane on 2018/5/21.
 */
public class BinaryFile extends AbstractTest {
    protected static final String TAG = BinaryFile.class.getName();

    @Override
    public void test(String[] args) {
        super.test(args);
    }

    @Override
    protected String getTag() {
        return TAG;
    }

    public static byte[] read(File file) {
        try {
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
            byte[] data = new byte[in.available()];
            in.read(data);
            IOUtils.close(in);
            return data;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    public static byte[] read(String filename) {
        if (StringUtils.isEmpty(filename)) {
            return null;
        }
        return read(new File(filename));
    }
}
